; anypic.asm
; Image data for the demo

	.export bltanypic

	.segment "RODATA"

; Bitmap data (RLE encoded for $FF)
anyimage:
; Bitmap data (96x140)
	; column 0
	.byte $ff, $02, $fc, $fc, $fc, $fc, $fc, $f8
	.byte $f8, $f8, $f8, $f1, $f1, $ff, $0e, $8e
	.byte $c6, $c4, $c4, $e0, $e0, $e0, $f0, $f1
	.byte $f1, $f1, $ff, $1c, $fe, $ff, $02, $e4
	.byte $ff, $02, $fe, $ff, $01, $fe, $ff, $02
	.byte $c0, $ff, $01, $fe, $ff, $02, $c0, $ff
	.byte $02, $fe, $ff, $01, $d5, $fd, $ff, $07
	.byte $fe, $bf, $9f, $9f, $8f, $8f, $87, $87
	.byte $83, $83, $81, $81, $c0, $40, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00
	; column 1
	.byte $ff, $02, $38, $38, $18, $18, $98, $98
	.byte $89, $09, $09, $c9, $c1, $ff, $0e, $31
	.byte $31, $32, $22, $02, $04, $84, $86, $86
	.byte $ce, $cf, $ff, $1d, $75, $ff, $01, $8c
	.byte $ff, $02, $24, $ff, $02, $fb, $ff, $01
	.byte $50, $ff, $02, $b5, $ff, $01, $99, $ff
	.byte $02, $12, $ff, $01, $df, $7f, $ff, $06
	.byte $8d, $3f, $f8, $fd, $ff, $02, $f0, $80
	.byte $86, $c0, $c0, $e8, $c0, $e7, $e0, $70
	.byte $70, $3f, $3f, $1f, $1f, $0f, $0f, $07
	.byte $07, $07, $07, $07, $06, $03, $03, $02
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00
	; column 2
	.byte $ff, $02, $c0, $c0, $44, $44, $06, $06
	.byte $06, $06, $86, $86, $c6, $ff, $02, $c4
	.byte $c4, $c7, $c7, $c7, $c7, $c7, $c7, $c7
	.byte $c7, $ff, $02, $87, $03, $23, $31, $71
	.byte $71, $71, $71, $21, $03, $07, $ff, $0e
	.byte $f1, $c1, $81, $8f, $8f, $9f, $9f, $8f
	.byte $8f, $81, $c1, $ff, $04, $c7, $ff, $01
	.byte $99, $ff, $02, $08, $ff, $01, $dd, $fe
	.byte $ff, $01, $c0, $ff, $02, $91, $ff, $01
	.byte $0f, $ff, $02, $20, $ff, $01, $f9, $f7
	.byte $ff, $04, $f8, $07, $ff, $01, $f3, $37
	.byte $ff, $01, $f8, $00, $02, $30, $00, $0c
	.byte $c0, $00, $38, $00, $00, $03, $7f, $ff
	.byte $09, $fe, $f3, $3f, $fe, $e0, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00
	; column 3
	.byte $ff, $02, $c6, $c6, $0f, $0f, $1f, $1f
	.byte $3f, $3f, $3f, $3f, $3f, $ff, $02, $06
	.byte $07, $1f, $1f, $1f, $1f, $1f, $1f, $1f
	.byte $1f, $ff, $02, $02, $00, $11, $11, $11
	.byte $03, $03, $11, $11, $11, $11, $ff, $02
	.byte $f0, $f0, $e0, $e0, $e4, $e4, $c4, $c0
	.byte $c0, $ce, $8e, $ff, $01, $c7, $81, $01
	.byte $18, $18, $38, $38, $18, $18, $01, $81
	.byte $ff, $04, $99, $ff, $01, $70, $ff, $02
	.byte $c8, $ff, $01, $dd, $f7, $ff, $01, $08
	.byte $ff, $02, $42, $ff, $04, $08, $ff, $01
	.byte $df, $04, $ff, $02, $fd, $07, $3f, $ff
	.byte $02, $fe, $f9, $80, $03, $30, $00, $04
	.byte $c0, $20, $0c, $80, $03, $30, $00, $80
	.byte $83, $ff, $07, $fc, $e1, $1f, $f8, $e0
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	; column 4
	.byte $ff, $02, $00, $00, $8e, $8e, $8e, $8e
	.byte $8c, $8c, $8c, $8c, $8c, $ff, $02, $30
	.byte $30, $10, $10, $00, $80, $84, $86, $c6
	.byte $c6, $ff, $02, $00, $00, $8c, $8c, $8c
	.byte $8c, $8c, $8c, $8c, $8c, $8c, $ff, $02
	.byte $f8, $f8, $f8, $f8, $78, $78, $78, $78
	.byte $38, $38, $38, $ff, $01, $9f, $8e, $86
	.byte $84, $80, $80, $81, $89, $8b, $8f, $8f
	.byte $ff, $04, $44, $ff, $01, $13, $ff, $02
	.byte $40, $ff, $01, $6c, $ff, $02, $3f, $ff
	.byte $02, $10, $ff, $04, $04, $ff, $02, $bf
	.byte $fc, $95, $df, $ff, $03, $fb, $b0, $00
	.byte $00, $00, $00, $40, $00, $00, $c0, $03
	.byte $38, $80, $00, $01, $1f, $ff, $06, $fc
	.byte $c0, $0e, $f0, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00
	; column 5
	.byte $ff, $02, $07, $03, $43, $41, $40, $40
	.byte $44, $44, $46, $47, $47, $ff, $02, $c0
	.byte $88, $88, $88, $18, $18, $18, $18, $38
	.byte $38, $ff, $02, $63, $63, $63, $63, $03
	.byte $03, $03, $63, $63, $63, $63, $ff, $02
	.byte $c6, $c4, $c4, $c4, $00, $00, $c0, $c4
	.byte $c4, $c6, $c7, $ff, $01, $30, $20, $20
	.byte $23, $23, $20, $20, $23, $23, $23, $23
	.byte $ff, $04, $35, $ff, $06, $e9, $e9, $ff
	.byte $03, $f7, $a1, $ff, $04, $3f, $ff, $01
	.byte $fe, $c0, $01, $3f, $ff, $02, $fd, $b0
	.byte $00, $00, $00, $00, $0c, $80, $00, $00
	.byte $00, $18, $80, $00, $00, $0f, $ff, $06
	.byte $fc, $c0, $00, $60, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00
	; column 6
	.byte $ff, $02, $88, $88, $08, $08, $08, $08
	.byte $08, $88, $88, $88, $88, $ff, $02, $8e
	.byte $8e, $8e, $8e, $8e, $8e, $8e, $8e, $82
	.byte $82, $ff, $02, $e0, $e0, $e2, $e2, $e0
	.byte $e0, $e2, $e2, $e2, $e0, $e0, $ff, $02
	.byte $0e, $06, $62, $e2, $e2, $e2, $e2, $62
	.byte $06, $06, $1e, $ff, $01, $f3, $23, $23
	.byte $23, $23, $23, $63, $e3, $e3, $e0, $f0
	.byte $ff, $03, $fe, $ea, $ff, $01, $e0, $ff
	.byte $01, $fe, $e0, $ff, $01, $fe, $fe, $ff
	.byte $01, $e0, $ff, $01, $fe, $fe, $ff, $05
	.byte $f0, $00, $0f, $ff, $02, $fe, $a4, $40
	.byte $00, $00, $00, $08, $80, $01, $10, $00
	.byte $0e, $c0, $00, $00, $0f, $ff, $06, $f8
	.byte $e0, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $03, $06, $06, $03, $00
	.byte $00, $00, $00, $11, $00, $12, $00, $00
	.byte $00, $00
	; column 7
	.byte $ff, $02, $1e, $1e, $fe, $fe, $1e, $1e
	.byte $fe, $fe, $fe, $1e, $1e, $ff, $02, $3f
	.byte $3f, $3f, $3f, $3f, $3f, $3f, $3f, $07
	.byte $07, $ff, $02, $63, $23, $23, $23, $63
	.byte $63, $23, $23, $23, $20, $70, $ff, $02
	.byte $38, $38, $10, $00, $00, $00, $4c, $6c
	.byte $6c, $7c, $7c, $ff, $01, $00, $00, $18
	.byte $18, $18, $18, $18, $18, $18, $18, $38
	.byte $ff, $03, $bf, $c0, $ff, $01, $88, $ff
	.byte $02, $81, $ff, $01, $da, $5e, $ff, $01
	.byte $1f, $ff, $01, $fe, $02, $ff, $03, $fc
	.byte $80, $03, $7f, $ff, $02, $fd, $40, $00
	.byte $00, $00, $03, $10, $00, $18, $80, $00
	.byte $f3, $07, $03, $07, $ff, $06, $f8, $80
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $df, $df, $80
	.byte $00, $00, $00, $00, $00, $00, $a9, $00
	.byte $00, $00, $00
	; column 8
	.byte $ff, $02, $39, $19, $19, $19, $09, $01
	.byte $01, $21, $21, $21, $31, $ff, $02, $01
	.byte $01, $11, $11, $03, $01, $19, $19, $11
	.byte $01, $ff, $02, $03, $03, $10, $10, $18
	.byte $18, $18, $18, $18, $38, $78, $ff, $02
	.byte $81, $81, $8f, $8f, $81, $81, $8f, $8f
	.byte $89, $81, $81, $ff, $01, $00, $00, $c0
	.byte $c7, $c7, $c0, $c0, $c7, $c7, $c0, $c0
	.byte $ff, $04, $10, $ff, $01, $60, $ff, $04
	.byte $99, $d6, $ff, $04, $82, $ff, $02, $f3
	.byte $7b, $1f, $ff, $03, $b7, $07, $01, $01
	.byte $00, $20, $00, $0c, $c0, $00, $03, $3f
	.byte $ff, $08, $f0, $80, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $ff, $01, $d5, $00, $49
	.byte $44, $04, $00, $90, $00, $b4, $00, $00
	.byte $00, $00
	; column 9
	.byte $ff, $02, $c3, $81, $10, $18, $18, $38
	.byte $18, $18, $00, $81, $c3, $ff, $02, $03
	.byte $03, $1f, $1f, $03, $03, $1f, $1f, $03
	.byte $03, $ff, $02, $02, $22, $22, $22, $62
	.byte $62, $e2, $e2, $e2, $e2, $e2, $ff, $0e
	.byte $83, $81, $80, $88, $88, $81, $81, $88
	.byte $88, $88, $8c, $ff, $04, $31, $ff, $01
	.byte $48, $ff, $05, $2b, $ff, $03, $fe, $60
	.byte $ff, $07, $03, $0f, $80, $c3, $e0, $f0
	.byte $f8, $fc, $3e, $1f, $1f, $ff, $08, $f8
	.byte $80, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $ff, $02, $00, $00, $0a, $00
	.byte $00, $e1, $00, $25, $00, $00, $00, $00
	; column 10
	.byte $ff, $02, $18, $18, $10, $90, $80, $80
	.byte $82, $c2, $c6, $c7, $e7, $ff, $0e, $31
	.byte $31, $11, $11, $10, $00, $40, $41, $61
	.byte $61, $71, $ff, $17, $9f, $9f, $ff, $04
	.byte $87, $ff, $01, $a1, $fd, $ff, $03, $bc
	.byte $79, $ff, $04, $bf, $ff, $0b, $3f, $ff
	.byte $01, $0f, $07, $1f, $ff, $08, $f0, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $e0, $60, $00, $00, $00
	.byte $00, $00, $14, $00, $ee, $00, $00, $00
	.byte $00
	; column 11
	.byte $ff, $02, $c7, $c7, $cf, $8f, $0f, $0f
	.byte $1f, $1f, $1f, $3f, $3f, $ff, $0e, $c1
	.byte $81, $09, $1f, $3f, $30, $30, $38, $08
	.byte $00, $81, $ff, $1c, $7f, $0f, $ff, $01
	.byte $11, $bf, $ff, $03, $e7, $6f, $ff, $1b
	.byte $f1, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $00, $00
	.byte $00, $00, $00, $00, $00, $00, $f0, $00
	.byte $00, $00, $00, $00, $00

	anysize = * - anyimage + 1
 
 	.segment "DATA"

bcounter:	.res 2
colcnt:		.res 1
 
	lines = 140
	blank = 20
 
	.segment "CODE"

; uncompress image to target bitmap (self-modifying code in pload & pstore!)
bltanypic:	; A/X ... target bitmap
			sta pstore+1
			stx pstore+2
			lda #<anysize
			sta bcounter
			lda #>anysize
			sta bcounter+1
			lda #<anyimage
			sta pload+1
			lda #>anyimage
			sta pload+2
			lda #lines
			sta colcnt
@loop:		jsr pload
			bcs @end
			cmp #$FF
			bne @stsmp
			jsr pload
			bcs @end
			tax
@unroll:	lda #$FF
			jsr pstore
			dex
			bne @unroll
			beq @loop
@stsmp:		jsr pstore
			jmp @loop
@end:		rts

	.segment "DATA"

pload:		lda $A000
			inc pload+1
			bne @goon
			inc pload+2
@goon:		clc
			dec bcounter
			bne @fin
			ldx bcounter+1
			bne @decc
			sec
@decc:		dec bcounter+1
@fin:		rts
			
pstore:		sta $A000
			inc pstore+1
			bne @goon
			inc pstore+2
@goon:		dec colcnt
			bne @fin
			lda #lines
			sta colcnt
			clc
			lda pstore+1
			adc #blank
			sta pstore+1
			bcc @fin
			inc pstore+2
@fin:		rts
